import React, { useState, useEffect } from 'react';
import { withRouter } from 'react-router-dom'
import { NavBar, Icon, List, Toast, Result, Button } from 'antd-mobile';
import { GetPreOrder,GetProducingOrders } from "@/api/order/order.js"

import _ from 'lodash';
import { R, ORDER_STATUSES } from "@/assets/js/dict.js"

import './other.scss';
import { Radio } from "antd-mobile/lib/radio";
import OrderDetailsOfEdit from "./parentOrderDetails/orderDetailsOfEdit";
import OrderDetailsOfAudit from "./parentOrderDetails/orderDetailsOfAudit";


import nodata from "@/assets/svg/nodata.svg"
import OrderDetailsOfPublish from "./parentOrderDetails/orderDetailsOfPublish";

const Item = List.Item;
const Brief = Item.Brief;
const myImg = src => <img src={src} className="spe am-icon am-icon-md" alt="" />;

/**
 * 找家教，新建订单、待定订单
 * @param props
 * @returns {*}
 * @constructor
 */
function LookForTutor (props) {
    console.log("props---> ", props);

    let [flush, setFlush] = useState("");
    let [msg, setMsg] = useState("暂无未发布的订单");

    function doFlush () {
        setFlush(new Date().getTime());
    }

    let [userInfo] = useState(() => {
        let userInfo = JSON.parse(sessionStorage.getItem("userInfo"));
        return userInfo
    }),
        [order, setOrder] = useState({ students: [], student_ids: "" });

    let [orderPaddingList,setOrderPaddingList] = useState([]); // 待定订单列表

    // 查询编辑中的订单列表信息
    function getOrderList () {
        GetProducingOrders({
            parent_id: userInfo.id
        }).then(res =>{
            if(res.code === "000000"){
                setOrderPaddingList([...res.responseData])
            }
        })
    }

    useEffect(() => {
        getOrderList();
    }, [flush]);

    //注意return中的是表达式，传来的是数据结构，不是真实的数据，真实数据将异步的加载、渲染，
    // 所以我们要尽量模拟数据结构，尤其是多层次的结构，需要特别设置，不然不会拼接出完整的表达式
    // 虚拟dom比较 是不是也跟这个有关呢？
    // if (!!order && !!order.status) {
    //     sessionStorage.setItem("order_id", order.id);
    //     if (order.status === ORDER_STATUSES.EDITING || order.status === ORDER_STATUSES.REJECTED) {
    //         return (<OrderDetailsOfEdit order_id={order.id} doFlush={doFlush} flushMain={props.flushMain} OrderDetailsData={order} />);
    //     } else {
    //         if (order.status === ORDER_STATUSES.AUDITING) {
    //             return (<OrderDetailsOfAudit order_id={order.id} doFlush={doFlush} flushMain={props.flushMain} OrderDetailsData={order} />);
    //         } else {
    //             return (<OrderDetailsOfPublish order_id={order.id} doFlush={doFlush} flushMain={props.flushMain} OrderDetailsData={order} />);
    //         }
    //     }
    // } else {

        return (<div className="other">
            <div className="page-title  home-tit">
                <NavBar
                    mode="light"
                    key={"1"}
                    icon={<Icon type="left" />}
                    // rightContent={[
                    //     <span key={"op"}>操作</span>
                    // ]}
                    onLeftClick={() => {
                        props.history.push({
                            pathname: '/main',
                            query: { selectedTab: "index" },
                        })
                    }}
                >
                    找家教
                </NavBar>
            </div>

            <div className="page-content  home-content">
                <div className="publish-content-piece">
                    <div className="form-box">
                        <div className="form-tit">
                            <i className="mini-block"></i>
                            <strong>待定订单</strong>
                        </div>
                        <div className="form-con" style={{height: '70vh', overflow:'auto'}}>
                            <List>
                                {
                                    orderPaddingList.length ?
                                        orderPaddingList.map(item => {
                                            return (
                                                <List.Item arrow="horizontal" multipleLine onClick={() => {
                                                    props.history.push({
                                                        pathname: '/OrderDetailsOfPublish',
                                                        query: { orderId: item.id  },
                                                    })
                                                    sessionStorage.setItem("order_id",item.id)
                                                }} key={item.id}>
                                                    提交时间：{item.commit_time}
                                                    <List.Item.Brief>
                                                    <p>
                                                        订单状态：<b>{item.status}</b>
                                                    </p>
                                                        对家教老师的要求： <br/>
                                                        {item.demand}
                                                    </List.Item.Brief>
                                                </List.Item>
                                            )
                                        })
                                    :
                                        <Result
                                            img={myImg(nodata, "none")}
                                            title=""
                                            message="暂无数据"
                                            buttonType="primary"
                                            style={{paddingBottom: '30px'}}
                                        />
                                }
                            </List>
                        </div> 
                        <Button type="primary" onClick={() => {
                            props.history.push('/orderDetailsOfEdit')
                        }}>新增订单</Button>
                    </div>
                </div>
            </div>
        </div>);

    // }


}

export default withRouter(LookForTutor);